<template>
  <div>
    <div v-for="item in goodsList" :key="item.id">
      <p>商品名字：{{item.goodsName}}</p>
      <p>商品价格：{{item.goodsPrice | currency}}</p>
      <p>上架时间：{{item.addTime | date}}</p>
      <button @click="joinCart(item)">加入购物车</button>
      <hr />
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "GoodsList",
  computed: {
    ...mapState({
      goodsList (state) {
        return state.goods.goodsList;
      }
    })
  },
  methods: {
    joinCart (goodsInfo) {
      this.$store.commit('JOIN_CART', goodsInfo);
      this.$router.push('/cartList')
    }
  }
}
</script>

<style scoped>
</style>